package com.deltapunkt.proxy;

import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

	
public class Secret {
	// ideally you would pass the function as a string - 'sin(tan(cos(sin(x)))), SHA'
	// & then parse it
	public static byte[] generate(double challenge) {
		double secret = Math.sin(challenge);
		secret = Math.cos(challenge);
		secret = Math.tan(challenge);
		secret = Math.sin(challenge);
		MessageDigest md = null;
		try {
			// good candidate for assert at startup - fail-fast idea
			md = MessageDigest.getInstance("SHA");
		} catch (NoSuchAlgorithmException e) {
			e.printStackTrace();
		}

		return md.digest((""+secret).getBytes());
	}
	
	public static boolean verify(byte[] v1, byte[] v2) {
		// better assert v1,v2 != null
		if (v1 == null || v2 == null || v1.length != v2.length) {
			return false;
		}

		for (int i = 0; i < v1.length; i++) {
			if (v1[i] != v2[i]) {
				return false;
			}
		}

		return true;
	}

}
